package com.spsoft.system.controller;

import com.spsoft.core.annotation.AnonymousAccess;
import com.spsoft.core.annotation.Log;
import com.spsoft.core.controller.BaseController;
import com.spsoft.core.enums.LogActionType;
import com.spsoft.core.enums.LogMenuEnum;
import com.spsoft.core.model.Result;
import com.spsoft.system.service.CacheUpdateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


@Api(tags = {"缓存更新 "})
@RestController
@RequestMapping("/cache")
@RequiredArgsConstructor
@Validated
@Slf4j
public class CacheUpdateController extends BaseController {

    private final CacheUpdateService cacheUpdateService;
    @CrossOrigin
    @ApiOperation("根据类型代码获取数据字典")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cacheCode", value = "缓存编码", dataTypeClass=String.class,dataType = "String", paramType = "query", required = true),
    })
    @AnonymousAccess(value = "/updateCache", method = RequestMethod.GET,permissionCode = "")
    @Log(value = "缓存更新", type = LogActionType.UPDATE,  menuName = LogMenuEnum.SYSTEM_BASIC_INFO)
    public Result getDefBIzdictByLxdm(String cacheCode) {
        response.setHeader("Access-Control-Allow-Origin","*");
        response.setContentType("text/json; charset=utf-8");
        response.setHeader("Access-Control-Allow-Methods","GET,POST,OPTIONS,DELETE");
        response.setHeader("Access-Control-Max-Age","3600");
        response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");


        return cacheUpdateService.updateCache(cacheCode);
    }
}
